from img_do import img_do
from img_do import shubiao
import time
import json
import random
from DrissionPage import ChromiumPage, SessionPage, Chromium
# 问题是无法导入 'playwright.sync_api'，通常是因为 Playwright 库未安装
# 可以通过以下命令安装 Playwright
# pip install playwright
# 安装完成后，还需要安装浏览器驱动
# playwright install

import requests
from db import insert_data, save_zip_files
import os

from playwright.sync_api import sync_playwright
from bs4 import BeautifulSoup

import pyperclip
import pyautogui



# 设置日志
img_do.setup_logging()

# 调用查找并点击图片偏移位置的函数
# img_do.find_and_click_point("./img/1.png", 6, 20)
# img_do.find_and_click_offset("./img/logo_user.png", 100, 0)
# 调用鼠标拖动函数，这里假设从 (100, 100) 拖动到 (200, 200)，持续时间为 1 秒
# img_do.mouse_drag_between_points("./img/huakuai.png", 4, 6, 5, 0.7)


# # 调用查找并点击图片偏移位置的函数
# img_do.find_and_click_point("./img/user.png", 5, 0)
# # 调用模拟键盘输入函数
# img_do.simulate_keyboard_input('15510016669')


# # 调用查找并点击图片偏移位置的函数
# img_do.find_and_click_point("./img/password.png", 5, 0)
# # 调用模拟键盘输入函数
# img_do.simulate_keyboard_input('maix6jiayou')

# # 调用鼠标拖动函数，这里假设从 (100, 100) 拖动到 (200, 200)，持续时间为 1 秒
# img_do.mouse_drag_between_points("./img/huakuai2.png", 4, 6, 5, 0.7)

# # 暂停
# time.sleep(2)

# # 调用查找并点击图片偏移位置的函数
# img_do.find_and_click_point("./img/login4.png", 5, 0)


def login():
    img_do.find_and_click_offset("./img/logo_user.png", 100, 0)
    img_do.simulate_keyboard_input('15510016669', 0)

    img_do.find_and_click_offset("./img/logo_password.png", 100, 0)
    img_do.simulate_keyboard_input('maix6jiayou', 0)

    img_do.mouse_drag_from_center("./img/logo_sou.png", 700, 0)

    time.sleep(2)
    img_do.find_and_click_offset("./img/logo_login.png", 0, 0)


def quzhheng_in():
    res = img_do.read_json_file("./证据名称数组.json")
    # 获取数组中随机一个元素
    res = random.choice(res)
    # print(res)

    import random
    random_number = random.randint(10**9, 10**10 - 1)
    
    # res = res + "（"+random_number+"）" 
    res = f"{res}({random_number})"
    
    # logo_zhengshu.png
    img_do.find_and_click_offset("./img/logo_zhengshu.png", 300, 0)
    time.sleep(1)  # import time

    # res = "456"
    # img_do.simulate_keyboard_input("123")
    img_do.simulate_keyboard_input(f"{res}")

    img_do.find_and_click_offset("./img/logo_beizhu.png", 300, 0)
    # print(res)
    time.sleep(1)
    img_do.simulate_keyboard_input(f"{res}")

    # logo_quzheng.png
    img_do.find_and_click_offset("./img/logo_quzheng.png", 0, 0)


def xiazai():
    img_do.find_and_click_point("./img/logo_zhengshu.png", 8, 10)
    shubiao.scroll_mouse('down', 1800)

    # 点击下载
    img_do.find_and_click_offset("./img/logo_xiazai.png", 0, 0)
    time.sleep(1)

    # 下载证书
    img_do.find_and_click_offset("./img/logo_xiazaizhengshu.png", 0, 0)
    time.sleep(4)

    # 点击下载
    img_do.find_and_click_offset("./img/logo_xiazai.png", 0, 0)
    time.sleep(1)
    # 下载证据
    img_do.find_and_click_point("./img/logo_xiazaizhengju2.png", 8, 10)
    time.sleep(1)
    # 下载证据确认
    img_do.find_and_click_point("./img/logo_lijixiazai2.png", 6, 20)


def quzhheng_start1(url):
    time.sleep(2)
    # logo_yuebuzuzhidaole.png 余额不足知道了
    img_do.find_and_click_point("./img/logo_yuebuzuzhidaole.png", 8, 0)
    time.sleep(2)

    # 点击谷歌浏览器
    img_do.find_and_click_point("./img/logo_google4.png", 5, 0)
    img_do.find_and_click_point("./img/logo_google4.png", 5, 0)
    img_do.find_and_click_point("./img/logo_google4.png", 5, 0)
    # 等 3 秒
    time.sleep(3)
    # 点击浏览器的导航栏
    img_do.find_and_click_point("./img/logo_daohanglan2.png", 5, 0)
    img_do.find_and_click_point("./img/logo_daohanglan2.png", 5, 0)
    time.sleep(2)

    shubiao.simulate_keyboard_delete(30)
    # 输入抖音网址
    # img_do.simulate_keyboard_input('111222')
    # img_do.simulate_keyboard_input(f"2344")
    shubiao.type_text(url)

    shubiao.simulate_keyboard_enter(1)

    # 等 5 秒
    time.sleep(10)
    # 点击抖音登录的关闭
    img_do.find_and_click_point("./img/logo_douyinguanbi2.png", 3, 0)
    time.sleep(2)
    # 点击抖音我知道了按钮
    # logo_wozhidaole.png
    img_do.find_and_click_point("./img/logo_wozhidaole.png", 5, 0)

    # 等待8分钟
    time.sleep(30)
    # time.sleep(8*60)
    # logo_wanchengquzheng.png
    img_do.find_and_click_point("./img/logo_wanchengquzheng.png", 4, 20)


def run2():
    # 1. 创建浏览器页面对象（默认使用 Chromium 内核）
    page = ChromiumPage()

    page.get("https://usercenter.tsa.cn/login")

    page.ele('@placeholder=请输入您的用户名/手机号/邮箱').input('15510016669')
    page.ele('@placeholder=请输入您的密码').input('maix6jiayou')

    page.ele('.nc_iconfont btn_slide').drag(offset_x=600, duration=2)

    if page.ele('.acitveBtn form-btn'):
        page.ele('.acitveBtn form-btn').click()

    # time.sleep(4)
    # page.get("https://ev.tsa.cn/vm_fetch")
    # page.ele('@placeholder=请输入您自定义的证据名称，如：**公司_商标侵权证据').input("1212312")
    # page.ele('@placeholder=选填，请填写取证证据的内容描述，如取证意图、关键词、证据标签等，便于后续查找使用').input("90789809")

    # # page.ele('.nextSetBtn ant-btn').click()
    # # time.sleep(10)

    # page = ChromiumPage()
    url = "https://ev.tsa.cn/api/evidenceRecorder?page=1&size=10&tabIdx=1&sourceAndRemark=&sharingStatus=&startTime=&endTime=&isChange=false"

    page.get(url)
    # 使用BeautifulSoup去除标签
    soup = BeautifulSoup(page.html, 'html.parser')
    pure_text = soup.get_text(separator='\n', strip=True)  # 保留换行并去除首尾空格
    # print(pure_text)

    # pure_text 转换成json
    json_data = json.loads(pure_text)

    data = json_data['pageInfo']['data']

    # print(data)

    # 写入数据库
    # insert_data('evidencerecorder', data)

    # 下载
    # 遍历数据列表，下载 zip 文件
    # save_zip_files(data, page)

    for i in data:
        folder_name = i['name']
        if 'pdfStorePath' in i:
            print("2")
            folder_name = i['name']
            if folder_name != "电脑端录屏取证操作示例":
                print("3")
                print("下载项目:", folder_name)
                pdf_file_url = i['pdfStorePath']
                applyFileStorePath = i['applyFileStorePath']
                # page.get(pdf_file_url)
                # page.get(applyFileStorePath)

                # 创建页面对象
                page = SessionPage()
                # 下载文件到指定路径
                save_path = os.path.normpath(os.path.join(
                    os.path.dirname(__file__), '../down', folder_name))
                page.download(pdf_file_url, save_path=save_path)
                page.download(applyFileStorePath, save_path=save_path)


# run2()

# save_path = os.path.normpath(os.path.join(os.path.dirname(__file__),'../down'))
# print(save_path)


# page = ChromiumPage()
# url = "https://ev.tsa.cn/api/evidenceRecorder?page=1&size=10&tabIdx=1&sourceAndRemark=&sharingStatus=&startTime=&endTime=&isChange=false"

# # 在新标签页打开网址
# new_tab = page.new_tab(url)  # 返回新标签页对象

# soup = BeautifulSoup(new_tab.html, 'html.parser')
# # 原代码报错可能是因为前面的代码存在多余的缩进，这里确保代码无多余缩进
# pure_text = soup.get_text(separator='\n', strip=True)  # 保留换行并去除首尾空格
# # print(pure_text)

# # pure_text 转换成json
# json_data = json.loads(pure_text)

# data = json_data['pageInfo']['data']

# print(data)
# # 关闭这个新标签页
# new_tab.close()  # 关闭当前标签页


def run():
    # from playwright.sync_api import sync_playwright
    # Set the download path
    download_path = os.path.join(os.getcwd(), 'downloads')
    os.makedirs(download_path, exist_ok=True)

    with sync_playwright() as p:
        # Launch the browser (in temporary guest mode)
        browser = p.chromium.launch(
            headless=False,  # Display the browser interface
            args=[
                "--disable-blink-features=AutomationControlled",  # Disable automation prompts
                "--guest",  # Enable guest mode (do not load user data)
                "--no-sandbox",  # 解决Windows权限问题（网页2）
                "--start-maximized"  # 最大化窗口（网页11）
            ]
        )
        # Create a context with download acceptance enabled
        # context = browser.new_context(accept_downloads=True)
        # 创建浏览器上下文（关键配置，网页1）
        context = browser.new_context(
            accept_downloads=True,
            # downloads_path='downloads',
            no_viewport=True  # 配合最大化参数
        )

        page = context.new_page()

        try:
            # Navigate to the target page
            page.goto("https://usercenter.tsa.cn/login")

            # Wait for the network to be idle
            page.wait_for_load_state("networkidle")

            # Timestamp website: https://ev.tsa.cn/vm_fetch
            # Account: 1: 15510016669   2: 15804644578   Password: maix6jiayou
            page.locator(
                ".from > .form-item:nth-child(1) > input").fill("15510016669")
            page.locator(".form-item:nth-child(2) > input").fill("maix6jiayou")

            # Locate the slider element
            slider = page.locator("span#nc_1_n1z")
            if slider.is_visible():
                # Get the bounding box information of the slider
                box = slider.bounding_box()
                if box:
                    # Simulate the mouse pressing down on the slider
                    page.mouse.move(box["x"] + box["width"] / 2,
                                    box["y"] + box["height"] / 2)
                    page.mouse.down()
                    # Simulate the mouse sliding to the right by 700px
                    page.mouse.move(box["x"] + box["width"] /
                                    2 + 700, box["y"] + box["height"] / 2)
                    # Simulate the mouse releasing
                    page.mouse.up()
                else:
                    print("Unable to get the bounding box information of the slider")
            else:
                print("The slider element is not visible")

            # Wait for the slider verification to complete (adjust the waiting time as needed)
            page.wait_for_timeout(3000)  # Wait for 3 seconds

            # Click the login button
            page.locator("div.form-btn").click()
            # Wait for the network to be idle
            page.wait_for_load_state("networkidle")

            # Click the electronic evidence collection jump button
            with context.expect_page() as new_page_info:
                page.locator(".el-button:nth-child(2) > span").click()
            new_page = new_page_info.value

            # Wait for the new page to load
            new_page.wait_for_load_state("networkidle")

            # Wait for the element .formName:nth-child(2) .ant-input
            new_page.wait_for_selector(
                ".formName:nth-child(2) .ant-input", timeout=10000)  # Increase the timeout

            # Wait for 3 seconds
            # new_page.wait_for_timeout(3000)  # Wait for 3 seconds

            res = img_do.read_json_file("./证据名称数组.json")
            # Get a random element from the array
            res = random.choice(res)

            # Perform subsequent operations on the new page
            new_page.locator(
                ".formName:nth-child(2) .ant-input").fill(res)
            new_page.locator(
                ".formName:nth-child(3) .ant-input").fill(res)

            # Initiate an API request
            url = "https://ev.tsa.cn/api/evidenceRecorder?page=1&size=20&tabIdx=1&sourceAndRemark=&sharingStatus=&startTime=&endTime=&isChange=false"
            try:
                # Use new_page.request to initiate a GET request
                response = new_page.request.get(url)
                # Check the response status code
                if response.ok:
                    json_data = response.json()
                    # Get the data from the 'data' section
                    data = json_data['pageInfo']['data']
                    print(data)
                    insert_data('evidencerecorder', data)
                    save_zip_files(data, new_page)

                    for i in data:
                        # Check if the child item has the 'pdfStorePath' field
                        if 'pdfStorePath' in i:
                            print(i)
                            # Extract the value of 'pdfStorePath'
                            pdf_file_url = i['pdfStorePath']
                            applyFileStorePath = i['applyFileStorePath']
                            # Extract the value of 'name'
                            folder_name = i['name']

                            # Construct the download path
                            download_folder = os.path.join(
                                download_path, folder_name)
                            os.makedirs(download_folder, exist_ok=True)

                            # Download the PDF zip file
                            with new_page.expect_download() as download_info:
                                new_page.goto(pdf_file_url)
                            download = download_info.value
                            pdf_path = os.path.join(
                                download_folder, 'certificate.zip')
                            download.save_as(pdf_path)

                            # Download the applyFile
                            with new_page.expect_download() as download_info_apply:
                                new_page.goto(applyFileStorePath)
                            download_apply = download_info_apply.value
                            apply_file_path = os.path.join(
                                download_folder, 'apply_file.zip')
                            download_apply.save_as(apply_file_path)

                else:
                    print(f"Request failed, status code: {response.status}")
            except Exception as e:
                print(f"An error occurred during the request: {e}")

        except Exception as e:
            print(f"An error occurred during the operation: {e}")

        # Wait for user input to avoid automatically closing the browser
        input("Press Enter to close the browser...")

        # Manually close the browser
        browser.close()


class AutoGui:
    """这是网络爬虫综合体现"""

    # 类属性（所有实例共享）
    class_attribute = "我是类属性"

    def __init__(self):
        """初始化方法（构造函数）"""
        # 当前路径
        self.__dirname = os.path.normpath(
            os.path.join(os.path.dirname(__file__)))

        # 全局 page
        # Chromium().latest_tab
        # ChromiumPage()
        self.page = ChromiumPage()

        # 15804644578
        # 15510016669
        # 18654815206
        # 15563309601
        self.username = '15563309601'
        self.password = 'maix6jiayou'

        self.data = ""

        self._isLogin = ''

        self._quzheng_url = ''

    def path(self, path):
        """路径"""
        return os.path.normpath(
            os.path.join(self.__dirname, path))

    @classmethod
    def class_method(cls):
        """类方法"""
        print(f"类方法被调用，类属性: {cls.class_attribute}")

    @staticmethod
    def static_method():
        """静态方法"""
        print("静态方法被调用，不接收self或cls参数")

    def demo(self):
        """实例方法"""
        print(self.__dirname)

    def login(self):
        """登录"""
        # comment: 
    
        # end try
        self.page.get("https://usercenter.tsa.cn/login")

        self.page.ele('@placeholder=请输入您的用户名/手机号/邮箱').input(self.username)
        self.page.ele('@placeholder=请输入您的密码').input(self.password)

        self.page.ele('.nc_iconfont btn_slide').drag(
            offset_x=600, duration=2)

        if self.page.ele('.acitveBtn form-btn'):
            self.page.ele('.acitveBtn form-btn').click()

        time.sleep(3)

    def is_login(self):
        """判断是否登录"""
        # 获取所有 Cookie（返回字典列表）
        # page = self.page
        # 获取当前页面所有 Cookie（返回字典列表）
        cookies = self.page.cookies(all_info=True)
        # print(cookies)
        # 检查是否存在 access_token
        has_access_token = any(cookie.get('name') ==
                               'access_token' for cookie in cookies)

        if has_access_token:
            print("access_token 存在,账号已登录")
            self._isLogin = True
            return True
        else:
            print("access_token 不存在,账号未登录")
            self._isLogin = False
            return False

    def login_out(self):
        """退出登录"""
        tab = Chromium().latest_tab
        tab.set.cookies.clear()
        self._isLogin = False
        print("已退出登录")

    def quzheng(self, do=""):
        """取证"""
        time.sleep(1.5)
        self.page.get("https://ev.tsa.cn/vm_fetch")

        # # 定位输入框元素
        # applicant_input = self.page.ele('placeholder=请输入申请人姓名/企业名称')
        # # 获取输入框内的文本内容
        # applicant_text = applicant_input.get_text()
        # # 判断文本内容是否为空
        # if not applicant_text.strip():
        #     # 若为空，则输入 "科研实验室"
        #     applicant_input.input("科研实验室")
    
        res = img_do.read_json_file("./证据名称数组.json")
        res = random.choice(res)
    
        # 获取数组中随机一个元素
        res = random.choice(res)
        # print(res)
    
        random_number = random.randint(10**9, 10**10 - 1)
        
        # res = res + "（"+random_number+"）" 
        res = f"{res}({random_number})"
    
        self.page.ele(
            '@placeholder=请输入您自定义的证据名称，如：**公司_商标侵权证据').input(res)
        self.page.ele(
            '@placeholder=选填，请填写取证证据的内容描述，如取证意图、关键词、证据标签等，便于后续查找使用').input(res)
    
        if do != "dev":
            time.sleep(2)
            self.page.ele('.nextSetBtn ant-btn').click()
            

    def getData(self):
        """获取数据"""
        # if self._isLogin == False:
        #     print("未登录")
        #     return False

        page = ChromiumPage()
        url = "https://ev.tsa.cn/api/evidenceRecorder?page=1&size=10&tabIdx=1&sourceAndRemark=&sharingStatus=&startTime=&endTime=&isChange=false"

        # 在新标签页打开网址
        new_tab = page.new_tab(url)  # 返回新标签页对象

        soup = BeautifulSoup(new_tab.html, 'html.parser')
        # 原代码报错可能是因为前面的代码存在多余的缩进，这里确保代码无多余缩进
        pure_text = soup.get_text(separator='\n', strip=True)  # 保留换行并去除首尾空格
        # print(pure_text)

        # pure_text 转换成json
        json_data = json.loads(pure_text)

        data = json_data['pageInfo']['data']

        print(data)
        # 关闭这个新标签页
        new_tab.close()  # 关闭当前标签页
        self.data = data
        return data

    def check_folder(self, folder_path):
        """检查文件夹是否存在"""
        if os.path.exists(folder_path) and os.path.isdir(folder_path):
            print(f"✅ 文件夹已存在,跳过本次下载: {folder_path}")
            return True
        else:
            print(f"❌ 文件夹不存在,下载凯斯: {folder_path}")
            return False

    def down(self):
        """下载资源"""
        if self.data == "":
            print("未获取到数据,先获取数据")
            return False
        data = self.data
        for i in data:
            folder_name = i['name']
            # 当文件夹不存在再下载
            if 'pdfStorePath' in i:
                # print("2")
                folder_name = i['name']
                if folder_name != "电脑端录屏取证操作示例":
                    if self.check_folder(self.path(f"../down/{folder_name}")) == False:
                        # print("3")
                        print("下载项目:", folder_name)
                        pdf_file_url = i['pdfStorePath']
                        applyFileStorePath = i['applyFileStorePath']
                        # page.get(pdf_file_url)
                        # page.get(applyFileStorePath)

                        # 创建页面对象
                        page = SessionPage()
                        # 下载文件到指定路径
                        save_path = os.path.normpath(os.path.join(
                            os.path.dirname(__file__), '../down', folder_name))
                        page.download(pdf_file_url, save_path=save_path)
                        page.download(applyFileStorePath, save_path=save_path)

    def set_db(self):
        if self.data == "":
            print("未获取到数据,先获取数据")
            return False
        insert_data('evidencerecorder', self.data)

    def quzhheng_start_ui(self, url, do=''):
        time.sleep(10)
        # logo_yuebuzuzhidaole.png 余额不足知道了
        img_do.find_and_click_point("./img/logo_yuebuzuzhidaole.png", 8, 0)
        time.sleep(2)

        # 点击谷歌浏览器
        img_do.find_and_click_point("./img/logo_google5.png", 5, 0)
        img_do.find_and_click_point("./img/logo_google5.png", 5, 0)
        # img_do.find_and_click_point("./img/logo_google5.png", 5, 0)

        # 等 3 秒
        time.sleep(2)
        # 点击浏览器的导航栏
        # img_do.find_and_click_point("./img/logo_daohanglan9.png", 5, 0)
        # img_do.find_and_click_point("./img/logo_daohanglan9.png", 5, 0)

        # 直接获取浏览器导航栏的焦点
        pyautogui.hotkey('ctrl', 'l')

        time.sleep(2)

        shubiao.simulate_keyboard_delete(30)
        # 输入抖音网址
        # img_do.simulate_keyboard_input('111222')
        # img_do.simulate_keyboard_input(f"2344")
        shubiao.type_text(url)

        shubiao.simulate_keyboard_enter(1)

        # 等 5 秒
        time.sleep(10)
        # 点击抖音登录的关闭
        img_do.find_and_click_point("./img/logo_douyinguanbi3.png", 3, 0)
        time.sleep(2)
        # 点击抖音我知道了按钮
        # logo_wozhidaole.png
        img_do.find_and_click_point("./img/logo_wozhidaole.png", 5, 0)


        # if do == "dev":
        #     # 等待8分钟
        #     time.sleep(18)
        #     img_do.find_and_click_point("./img/logo_wanchengquzheng5.png", 4, 20)
        #     # img_do.find_and_click_point("./img/logo_queding4.png", 9, 10)
        #     img_do.find_and_click_point("./img/logo_queding4.png", 9, 10)

        # else:

        #     time.sleep(18)
        #     # logo_wanchengquzheng.png
        #     img_do.find_and_click_point("./img/logo_wanchengquzheng5.png", 6, 20)

        #     # 确定退出
        #     # img_do.find_and_click_point("./img/logo_queding4.png", 9, 10)
        #     img_do.find_and_click_point("./img/logo_queding4.png", 9, 10)



        time.sleep(8*60)
        # logo_wanchengquzheng.png
        img_do.find_and_click_point("./img/logo_wanchengquzheng5.png", 6, 20)

        # 确定退出
        # img_do.find_and_click_point("./img/logo_queding4.png", 9, 10)
        img_do.find_and_click_point("./img/logo_queding4.png", 9, 10)


    def read_high_risk_works(self, dir_path, file_name):
        """
        读取指定路径下的高危作品.txt文件内容，并将每一行数据作为数组元素返回。
        :param dir_path: 高危作品.txt文件所在的目录的绝对路径
        :param file_name: 高危作品.txt文件名
        :return: 包含文件每一行内容的列表
        """
        file_path = os.path.join(dir_path, file_name)
        try:
            with open(file_path, 'r', encoding='utf-8') as file:
                lines = file.readlines()
                # 去除每行末尾的换行符
                return [line.strip() for line in lines]
        except FileNotFoundError:
            print(f"未找到文件: {file_path}")
            return []
        except Exception as e:
            print(f"读取文件时发生错误: {e}")
            return []

# 正式###############################################################



gui = AutoGui()
# gui.is_login()




# gui._quzheng_url = "https://www.douyin.com/video/7473281041080323328"
# gui.quzhheng_start("dev")  # 取证 gui 操作,需要做适配


def on_run():
    """启动条件,监听 高危作品.txt 文件内容来作为启动条件"""
    runnum = 0
    while(1):
        try:
            time.sleep(5)
            gaoweipath = gui.path("../static/")
            # 读取指定路径下的 高危作品.txt 文件内容
            res = gui.read_high_risk_works(gaoweipath, "高危作品.txt")
            
            

            print(res)
            # 如果是空,跳过
            if len(res) == 0:
                continue
            # 如果不是,就遍历数组,执行取证操作
            for i in res:
                print("开始取证:", i)
                runnum = runnum + 1
                print(f"开始第{runnum}次完整流程")
                gui.login_out()
                gui.login()  # 登录
                gui.quzheng()  # 取证
                gui.quzhheng_start_ui(i)  # 取证 gui 操作,需要做适配
                time.sleep(5)
                gui.getData()  # 获取数据
                gui.set_db()  # 写入数据库
                gui.down()  # 下载
                time.sleep(1)
                img_do.find_and_click_point("./img/logo_queding4.png", 9, 10)




            time.sleep(5)


            # 清空高危作品.txt 文件内容
            file_path = os.path.join(gaoweipath, "高危作品.txt")
            try:
                with open(file_path, 'w', encoding='utf-8') as file:
                    file.write('')  # 写入空字符串以清空文件
            except Exception as e:
                print(f"清空文件时发生错误: {e}")


        except Exception as e:
            print(f"意外,跳过本次: {e}")
            continue
       





on_run()



# 测试###############################################################
# run()


# 登录账号
# login()

# # 暂停5秒
# time.sleep(5)
# quzhheng_in()
# time.sleep(20)
# quzhheng_start("https://www.douyin.com/video/7473281041080323328")
# xiazai()

# llq_login()
